package hu;

import java.util.*;

public class hu65 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.nextLine();
        String s2 = sc.nextLine();
        int l1 = s1.length();
        int l2 = s2.length();
        if(l2 < l1){
            String s = s1;
            s1 = s2;
            s2 = s;
        }
        /**
         * 方法1 暴力解法
         */
//        int b = 0, e = 0;
//        int p = 0, q = 0;
//        int len = 0;
//        for (int i = 0; i < s1.length(); i++) {
//            for (int j = 0; j < s2.length(); j++) {
//                if(s1.charAt(i) == s2.charAt(j)){
//                    b = i;
//                    for (int k = i, l = j; k < s1.length() && l < s2.length(); k++, l++) {
//                        e = k;
//                        if(s1.charAt(k) != s2.charAt(l))
//                            break;
//                    }
//                    if(len < e - b){
//                        len = e - b;
//                        p = b;
//                        q = e;
//                    }
//                }
//            }
//        }
//        if(q == l1 - 1)
//            System.out.println(s1.substring(p, q + 1));
//        else
//            System.out.println(s1.substring(p, q));


        /**
         * 方法二 动态规划
         */
        int[][] dp = new int[s1.length() + 1][s2.length() + 1];
        int bb = 0;
        int len2 = 0;
        for (int i = 1; i <= s1.length(); i++){
            for (int j = 1; j <= s2.length(); j++) {
                if(s1.charAt(i - 1) == s2.charAt(j - 1))
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                if(dp[i][j] > len2){
                    len2 = dp[i][j];
                    bb = i;
                }
            }
        }
        System.out.println(s1.substring(bb - len2, bb));
    }
}
